package cn.core.act.interceptors;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * 工作流 >>> 配置流程引擎
 */
@Configuration
public class ActivitiSpringProcessEngineConfiguration implements ProcessEngineConfigurationConfigurer {

  @Resource
  private DataSource dataSource;

  @Value("${spring.activiti.data-source-name}")
  private String dataSourceName;

  @Override
  public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
    springProcessEngineConfiguration.setDataSource(((DynamicRoutingDataSource) dataSource).getDataSource(dataSourceName));
  }

}
